//
//  ZFMapManager+camera.swift
//  map
//
//  Created by fyzq on 2024/2/2.
//

import Foundation
import MapboxMaps
extension ZFMapManager {
    
    ///跳转定位
    func fly(options:CameraOptions,duration:TimeInterval = 0.5,completion: AnimationCompletion? = nil){
        guard let mapView = mapView else {
            return
        }
        mapView.camera.fly(to: options,duration: duration,completion: completion)
    }
    
    func location(){
        guard let mapView = mapView,
            let coordinate = mapView.location.latestLocation?.coordinate else {
            return
        }
        fly(options: CameraOptions(
            center: coordinate,
            zoom: 15
        ))
    }
    
    func changePitch(){
        guard let mapView = mapView else {
            return
        }
        let pitch = mapView.mapboxMap.cameraState.pitch
        let start:CGFloat = pitch > 44 ? 0 : 85 ;
        fly(options: CameraOptions(pitch: start),duration: 0.3)
    }
    
}
